import { defineStore } from 'pinia'
//user为id是必传的
export const userStore = defineStore('user', {
    state: () => {
        return {
            access_token: '', // token
            token_type: '',
            userInfo: {}
        }
    },
    actions: {
        //设置token的方法
        setToken(params) {
            this.access_token = params.access_token
            this.token_type = params.token_type
        },
        //清空token的方法
        clearToken() {
            this.access_token = ''
            this.token_type = ''
            this.userInfo = {}
        },
        //获取用户信息
        setUserInfo(ctx) {
            this.userInfo = ctx
        }
    },
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'user',
                storage: sessionStorage
            }
        ]
    }
})
